<?php

require_once '../config/config.php';

class db {

    public $connection;

    public function connect() {
         $this->connection = mysql_connect(DB_HOST . ":" . DB_PORT, DB_USER, DB_PASS) or die(mysql_error());
        mysql_select_db(DB_NAME, $this->connection);
        return $this->connection;
    }
    

    public function query($query) {
        $datas = array();
        mysql_query("SET NAMES utf8", $this->connection);
        $query = mysql_query($query, $this->connection);
        while ($row = mysql_fetch_assoc($query))
            $datas[] = $row;
        return $datas;
    }
    
      public function keywork(){      
            $this->connect();
            $query = "SELECT * FROM keywords WHERE LENGTH(name) > 10";
            $keywords = $this->query($query);
            return $keywords;
    }
    
    public function works() {
        $this->connect();
        $query = "SELECT * FROM works LIMIT 0,10";
        $work = $this->query($query);
        return $work;
    }    
     public function ptrang(){
         
                $trang1 = 10;
                if (!isset($_GET['page'])) {
                    $page = 0;
                } else {
                    $page = (int) $_GET['page'];
                }
                $dulieu = mysql_num_rows(mysql_query("SELECT * FROM works ")) or die(mysql_error());
                $tongtrang = 10;
                $trang = $page * $trang1;
                $result = mysql_query("SELECT * FROM works LIMIT {$trang},{$trang1} ") or die(mysql_error());
                $max = $tongtrang;
                $a = 5;?>
<br>
    
                   <table border ="2">
                <tr>
                    <td> Id </td>
                    <td> Name </td>
                    <td>Description</td>
                    <td>location</td>
                    <td>Image</td>
                    <td>--K--</td>
                    
                    <?php
                while ($info = mysql_fetch_array($result)) { ?>
                 <tr>
                        <td> <?php echo $info['id']; ?></td>
                        <td> <?php echo (substr( $info['name'],0,50)); ?></td> 
                         <td><?php echo substr($item['description'], 0, 100); ?></td>
                        <td> <?php echo $info['location']; ?></td>
                        <td> <img src=''></td>
                         <td><a href="edit.php?id=<?php echo $info["id"];?>">  edit  </a> <br>                                     
                             <a href>* View </a><br>
                             <a href>* Detele </a></td>
                    </tr>
                <?php
                }
                echo "<a href='index.php?page=1'> Frist </a>";
                for ($page = 1; $page <= $tongtrang; $page++) {

                    echo "<a href='index.php?page={$page}'> [{$page}]</a>";
                }
                echo "<a href='index.php?page={$max}'> Last <br></a>";
                
     }

}
?>
                   </table>

